﻿using SnakeGame.Lesson1;
using SnakeGame.Lesson3;
using SnakeGame.Lesson6;
using System;

namespace SnakeGame.Lesson4
{
    internal class Food : GameObject
    {
        public Food(Snake snake)
        {
            RandomPosition(snake);
        }

        public override void Draw()
        {
            Console.SetCursorPosition(position.x, position.y);
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write("●");
        }

        // 随机生成食物的位置
        public void RandomPosition(Snake snake)
        {
            // 判断位置是否与蛇身重叠
            do
            {
                // 随机位置
                Random random = new Random();
                int x = random.Next(2, Game.width / 2 - 1) * 2;
                int y = random.Next(1, Game.height - 4);
                position = new Position(x, y);

            } while (snake.CheckFoodCollision(position));
        }
    }
}